This application is based on application No. H10-299553 filed in Japan, the content of which is hereby incorporated by reference.
1. Field of the Invention
The present invention relates to a program conversion apparatus, and in particular to a so-called binary translator which converts an object program that is designed to run in a given execution environment into an object program that can run in a different execution environment.
2. Background Art
Binary translators receive object programs that are designed to run on certain platforms, convert the received object programs into object programs that can run on other platforms, and output the generated object programs. It should be noted here that the conversion of object programs means the generation of outputted programs from inputted object programs.
Here, the term xe2x80x9cobject programxe2x80x9d means a program in the executable format on a certain platform, such as a program that includes machine instructions generated by compiling a source program written in a high-level language. Also, the term xe2x80x9cplatformxe2x80x9d means a basic environment in which an object program is executed, such as a real processor, basic functions of an OS (operating system), and a virtual machine.
The selection of a platform is an important concern in the design of a computer system or a home appliance, since this places various restrictions, such as the instruction format, on the object programs that will run on such system. To generate object programs that satisfy these restrictions, a compiler that converts a source program written in a high-level language into an intermediate representation and converts the intermediate representation into an object program that conforms to a target platform may be used.
A conventional binary translator uses similar techniques to a compiler to convert an object program into an object program that satisfies the restrictions of the target platform. That is, a conventional binary translator converts an inputted program into an intermediate representation which includes contents of instructions and data that are extracted from the inputted program, and generates an object program that conforms to the target platform according to the intermediate representation.
As new program development techniques have been devised, more and more object programs are now designed to call libraries. As a result, certain object programs cannot run by themselves on platforms.
Here, the term xe2x80x9clibraryxe2x80x9d is a generic name for program modules that are external to object programs and can be called by the object programs. External program modules are, for instance, parts of OSs and function libraries including standard input-output functions of C language.
Object programs that include library calls pass arguments to call libraries, receive return values that are execution results from the libraries, and use the return values. Therefore, object programs are written so that they meet the conditions and requirements concerning arguments and return values for the libraries called by the object programs.
As a result, in recent years, the execution environments of object programs have come to include libraries in addition to platforms that are conventionally included in the execution environments.
Therefore, the conversion by conventional binary translators is not effective when the execution environments for object programs outputted from the binary translators does not include the same libraries as the execution environments for object programs before the conversion by the binary translators. Note that the same libraries before and after the conversion means libraries that are the same except for differences caused by the differences between platforms.
In other words, even if the conventional binary translators that are designed to overcome the differences between platforms are used to convert inputted object programs into other object programs corresponding to target platforms, the generated object programs cannot be executed due to the lack of the called library.
In view of the stated problems, the object of the present invention is to provide a program conversion apparatus (a binary translator) for converting an inputted object program that calls libraries into an outputted object program that runs in an execution environment which includes libraries that are different from the libraries called by the inputted object program.
The stated object is achieved by a program conversion apparatus for converting a first object program that runs on a first platform into a second object program that runs on the second platform, the first object program including source library call instructions that call source libraries, the source libraries being external modules that are designed to run on the first platform, the program conversion apparatus including: a library correspondence information storing unit for holding library correspondence information that associates the source libraries with target libraries and includes argument correspondence information, where the target libraries are external modules each of which is capable of running on the second platform and has the same feature as one of the source libraries, and the argument correspondence information shows a correlation between conditions required by source arguments and conditions required by target arguments, the source arguments being arguments of the source libraries and the target arguments being arguments of the target libraries; a library call instruction detecting unit for detecting a source library call instruction included in the first object program; an instruction converting unit for converting the detected source library call instruction into a target library call instruction by referring to the library correspondence information, where the target library call instruction is to be included in the second object program and calls a target library corresponding to a source library called by the detected source library call instruction; an argument setting instruction detecting unit for detecting an argument setting instruction included in the first object program, the argument setting instruction setting a value in a source argument of the called source library; and an argument setting instruction converting unit for converting the detected argument setting instruction into a target argument setting instruction by referring to the argument correspondence information, where the target argument setting instruction is to be included in the second object program and sets the value set in the source argument of the called source library as a target argument of the corresponding target library to meet a condition required by the target argument of the corresponding target library.
The following is the explanation of the reason why the stated object is achieved by the program conversion apparatus having this construction.
In some cases, even if the same libraries as the source libraries called by the first object program do not exist on the second platform, target libraries that have the same features as the source libraries exist on the second platform. It should be noted here that in this specification, the term xe2x80x9csame featuresxe2x80x9d of libraries means the same functions of the libraries. For instance, when libraries having the same features are executed, the same execution results are obtained. In other words, there are cases where even if the same libraries as the source libraries called by the first object program do not exist on the second platform, the execution environment of the first object program is similar to that of the second object program. An example of such is where to perform a general function of displaying a character sequence on a screen, a source library receives (1) a pointer specifying a memory area for storing the character string as the first argument and (2) 1-byte data showing the number of bytes of the character string as the second argument, and a target library receives (a) 2-byte data showing the number of bytes of the character string as the first argument and (b) a pointer specifying a memory area for storing the character string as the second argument.
In this case, there are various differences between the source library and target library, such as the difference in the interface between an object program and libraries, the difference in the number of arguments, difference in the number assigned to each argument, and the difference in the data type of each argument. The program conversion apparatus of the present invention overcomes these differences, thereby achieving the stated object.
When the second platform does not include the target library having the same feature as a source library, the target library may be generated and exist on the second platform, or the target library may be included in the second object program as an internal module. To include the internal module in the second object program, the difference in interface between an object program and libraries needs to be overcome. There are some cases where new target libraries that are the same as source libraries cannot be generated. This is because, in some cases, target libraries which each include the features of a plurality of similar source libraries needs to be generated to efficiently use memories, and the variation of data types that can be dealt with by processors are limited due to various factors such as the poor performances of the processors.
Here, the argument correspondence information may include target argument type information showing data types that are the conditions required by the target arguments and source argument type information showing data types that are the conditions required by the source arguments, and the argument setting instruction converting unit may convert, by referring to the target argument type information and source argument type information, the detected argument setting instruction into the target argument setting instruction, where the target argument setting instruction converts a data type of the value set by the detected argument setting instruction into a data type of the target argument of the corresponding target library shown by the target argument type information and sets the value of the converted data type as the target argument of the corresponding target library.
With this construction, even if the data type of a source argument is different from that of a target argument, the program conversion apparatus of the present invention overcomes the difference in the data types by converting the data type of the source argument into that of the target argument. Therefore, an object program including library call instructions for calling source libraries is appropriately converted into an object program that calls target libraries.
The stated object is also achieved by a program conversion apparatus for converting a first object program that runs on a first platform into a second object program that runs on the second platform, the first object program including source library call instructions that call source libraries, the source libraries being external modules that are designed to run on the first platform, the program conversion apparatus including: a library correspondence information storing unit for holding library correspondence information that associates the source libraries with target libraries and includes argument correspondence information, where the target libraries are external modules each of which is capable of running on the second platform and has the same feature as one of the source libraries, and the argument correspondence information shows a correlation between conditions required by source arguments and conditions required by target arguments, the source arguments being arguments of the source libraries and the target arguments being arguments of the target libraries; a library call instruction detecting unit for detecting a source library call instruction included in the first object program; an instruction converting unit for converting the detected source library call instruction into a target library call instruction by referring to the library correspondence information, where the target library call instruction is to be included in the second object program and calls a target library corresponding to a source library called by the detected source library call instruction; an argument setting instruction detecting unit for detecting an argument setting instruction included in the first object program, the argument setting instruction setting a value in a source argument of the called source library; an argument setting instruction converting unit for converting the detected argument setting instruction into a target argument setting instruction by referring to the argument correspondence information, where the target argument setting instruction is to be included in the second object program and sets the value set in the source argument of the called source library as a target argument of the corresponding target library to meet a condition required by the target argument of the corresponding target library; and an internal module linking unit for linking the corresponding target library with the second object program as an internal module.
With this construction, even if a library having the same feature as a source library does not exist on the second platform, the library is linked with the second object program as an internal module. Therefore, the second object program is executable on the second platform.
The stated object is further achieved by a program conversion apparatus for converting a first object program that runs on a first platform into a second object program that runs on the second platform, the first object program including source library call instructions that call source libraries, the source libraries being external modules that are designed to run on the first platform, the program conversion apparatus including: a library correspondence information storing unit for holding library correspondence information that associates the source libraries with target libraries and includes return value correspondence information, where the target libraries are external modules each of which is capable of running on the second platform and has the same feature as one of the source libraries, and the return value correspondence information shows a correlation between attributes of source return values and attributes of target return values, the source return values being values returned from the source libraries and the target return values being values returned from the target libraries; a library call instruction detecting unit for detecting a source library call instruction included in the first object program; an instruction converting unit for converting the detected source library call instruction into a target library call instruction by referring to the library correspondence information, where the target library call instruction is to be included in the second object program and calls a target library corresponding to a source library called by the detected source library call instruction; a return value using instruction detecting unit for detecting a return value using instruction included in the first object program, the return value using instruction using a source return value returned from the called source library; and a return value using instruction converting unit for converting the detected return value using instruction into a target return value using instruction by referring to the return value correspondence information, where the target return value using instruction is to be included in the second object program, converts a target return value returned from the corresponding target library to conform to an attribute of the returned source return value, and uses the converted target return value.
With this construction, even if the attributes of return values returned from source libraries are different from those of return values returned from target libraries, the second object program is executable on the second platform.
Here, the return value correspondence information may include source return value type information showing data types that are the attributes of the source return values and target return value type information showing data types that are the attributes of the target return values, and the return value using instruction converting unit may convert, by referring to the source return value type information and target return value type information, the detected return value using instruction into the target return value using instruction, where the target return value using instruction converts a data type of the target return value returned from the corresponding target library into a data type of the returned source return value shown by the source return value type information and uses the target return value of the converted data type.
With this construction, even if the attributes of return values returned from source libraries are different from those of return values returned from target libraries, the attributes of the source return values are converted into those of the target return values. Therefore, an object program including library call instructions for calling source libraries is appropriately converted into an object program that calls target libraries.
As described above, the program conversion apparatus of the present invention overcomes the difference between execution environments, which is to say the difference between external program modules called by object programs, in addition to the difference between platforms. Therefore, the program conversion apparatus of the present invention converts an inputted object program into an outputted object program that can run in a target execution environment. As a result, the present invention has great practical uses.